package com.minibobbo.utilities.spe.controlmodule;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.minibobbo.utilities.spe.SimplePlatformEngine;
import com.minibobbo.utilities.spe.SpeDynamicObject;

public abstract class SpeControlModule {
	SimplePlatformEngine e;
	SpeDynamicObject parent;
	
	private int u,d,l,r;
	private int[] b;
	
	public void init(SimplePlatformEngine engine, SpeDynamicObject parent) {
		e = engine;
		this.parent = parent;
		b = new int[8];
		
		setAllKeys();
	}
	
	public void assignUp(int key) {
		 u = key;
	}
	public void assignDown(int key) {
		 d = key;
	}
	public void assignLeft(int key) {
		 l = key;
	}
	public void assignRight(int key) {
		 r = key;
	}
	
	
	
	public SpeControlModule assignButton(int button, int key) {
		b[button] = key;
		return this;
	}
	
	public abstract void setAllKeys();
	
	public void updateControl(float delta) {
		parent.resetMovementVariables();
		parent.resetButtonVariables();
		
		if(Gdx.input.isKeyPressed(u))
			parent.u = true;
		if(Gdx.input.isKeyPressed(d))
			parent.d = true;
		if(Gdx.input.isKeyPressed(l))
			parent.l = true;
		if(Gdx.input.isKeyPressed(r))
			parent.r = true;
		
		for(int i=0; i < b.length;i++) {
			if(Gdx.input.isKeyPressed(b[i]))
				parent.b[i] = true;
		}
		
	}
	


}
